home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / dayquote / dayquote.bas next >
Encoding:
BASIC Source File  |  1995-05-09  |  29.4 KB  |  834 lines

  1.     DefInt A-Z
  2.  
  3.     CONST FALSE = 0
  4.     CONST TRUE = 1
  5.  
  6.     DECLARE SUB DoQuote (FileName$)
  7.     DECLARE SUB ParseCommandLine (Num%, Arg$())
  8.     DECLARE SUB PutQuote (Text$)
  9.     DECLARE SUB PrintDoc (FileName$)
  10.     DECLARE SUB ShowGimme ()
  11.     DECLARE SUB ShowHelp ()
  12.     DECLARE SUB ShowSyntax ()
  13.  
  14.     DIM ErrorString$(76): FOR j = 1 TO 76: READ ErrorString$(j): NEXT
  15.     Dim Arguments$(1 To 20)
  16.     Dim Shared QuoteText$(1 To 22)
  17.     Dim Shared ForeColor, BackColor, Justification
  18.     Dim Shared StartCol, EndCol, TopLine, WipeScreen
  19.  
  20.     PRINT
  21.    
  22.     CALL ParseCommandLine(NumArgs%, Arguments$())
  23.  
  24.     IF Arguments$(1) = "" THEN ShowSyntax
  25.  
  26.     FOR i = 1 TO NumArgs%
  27.         SELECT CASE LEFT$(Arguments$(i), 2)
  28.         CASE "/?"
  29.             ShowHelp
  30.         CASE "/F"
  31.             IF MID$(Arguments$(i), 3, 1) = ":" THEN
  32.                 ExpectedArg$ = MID$(Arguments$(i), 4, LEN(Arguments$(i)))
  33.                 SELECT CASE ExpectedArg$
  34.                 CASE "BLACK", "BLK"
  35.                     ForeColor% = 1
  36.                 CASE "BLUE", "BLU"
  37.                     ForeColor% = 2
  38.                 CASE "GREEN", "GRN"
  39.                     ForeColor% = 3
  40.                 CASE "CYAN", "CYA"
  41.                     ForeColor% = 4
  42.                 CASE "RED"
  43.                     ForeColor% = 5
  44.                 CASE "MAGENTA", "MAG"
  45.                     ForeColor% = 6
  46.                 CASE "BROWN", "BRN"
  47.                     ForeColor% = 7
  48.                 CASE "WHITE", "WHT"
  49.                     ForeColor% = 8
  50.                 CASE "GRAY", "GREY", "GRY"
  51.                     ForeColor% = 9
  52.                 CASE "LTBLUE", "LBL"
  53.                     ForeColor% = 10
  54.                 CASE "LTGREEN", "LGR"
  55.                     ForeColor% = 11
  56.                 CASE "LTCYAN", "LCY"
  57.                     ForeColor% = 12
  58.                 CASE "LTRED", "LRD"
  59.                     ForeColor% = 13
  60.                 CASE "LTMAGENTA", "LMG"
  61.                     ForeColor% = 14
  62.                 CASE "YELLOW", "YEL"
  63.                     ForeColor% = 15
  64.                 CASE "BRWHITE", "BRW"
  65.                     ForeColor% = 16
  66.                 CASE ELSE
  67.                     CommandError = TRUE
  68.                     PRINT "Invalid foreground specification:  "; ExpectedArg$
  69.                 END SELECT
  70.                 ExpectedArg$ = ""
  71.             ELSE
  72.                 CommandError = TRUE
  73.                 PRINT "Missing colon in switch:  "; Arguments$(i)
  74.             END IF
  75.         CASE "/B"
  76.             IF MID$(Arguments$(i), 3, 1) = ":" THEN
  77.                 ExpectedArg$ = MID$(Arguments$(i), 4, LEN(Arguments$(i)))
  78.                 SELECT CASE ExpectedArg$
  79.                 CASE "BLACK", "BLK"
  80.                     BackColor% = 1
  81.                 CASE "BLUE", "BLU"
  82.                     BackColor% = 2
  83.                 CASE "GREEN", "GRN"
  84.                     BackColor% = 3
  85.                 CASE "CYAN", "CYA"
  86.                     BackColor% = 4
  87.                 CASE "RED"
  88.                     BackColor% = 5
  89.                 CASE "MAGENTA", "MAG"
  90.                     BackColor% = 6
  91.                 CASE "BROWN", "BRN"
  92.                     BackColor% = 7
  93.                 CASE "WHITE", "WHT"
  94.                     BackColor% = 8
  95.                 CASE "GRAY", "GREY", "GRY"
  96.                     BackColor% = 9
  97.                 CASE "LTBLUE", "LBL"
  98.                     BackColor% = 10
  99.                 CASE "LTGREEN", "LGR"
  100.                     BackColor% = 11
  101.                 CASE "LTCYAN", "LCY"
  102.                     BackColor% = 12
  103.                 CASE "LTRED", "LRD"
  104.                     BackColor% = 13
  105.                 CASE "LTMAGENTA", "LMG"
  106.                     BackColor% = 14
  107.                 CASE "YELLOW", "YEL"
  108.                     BackColor% = 15
  109.                 CASE "BRWHITE", "BRW"
  110.                     BackColor% = 16
  111.                 CASE ELSE
  112.                     CommandError = TRUE
  113.                     PRINT "Invalid background specification:  "; ExpectedArg$
  114.                 END SELECT
  115.                 ExpectedArg$ = ""
  116.             ELSE
  117.                 CommandError = TRUE
  118.                 PRINT "Missing colon in switch:  "; Arguments$(i)
  119.             END IF
  120.         CASE "/L"
  121.             IF LEN(Arguments$(i)) = 2 THEN
  122.                 IF NOT (Justification) THEN
  123.                     Justification = 1
  124.                 ELSE
  125.                     CommandError = TRUE
  126.                     PRINT "Multiple text justifications are not allowed:  "; Arguments$(i)
  127.                 END IF
  128.             ELSE
  129.                 CommandError = TRUE
  130.                 PRINT "Invalid switch:  "; Arguments$(i)
  131.             END IF
  132.         CASE "/C"
  133.             IF LEN(Arguments$(i)) = 2 THEN
  134.                 IF NOT (Justification) THEN
  135.                     Justification = 2
  136.                 ELSE
  137.                     CommandError = TRUE
  138.                     PRINT "Multiple text justifications are not allowed:  "; Arguments$(i)
  139.                 END IF
  140.             ELSE
  141.                 CommandError = TRUE
  142.                 PRINT "Invalid switch:  "; Arguments$(i)
  143.             END IF
  144.         CASE "/R"
  145.             IF LEN(Arguments$(i)) = 2 THEN
  146.                 IF NOT (Justification) THEN
  147.                     Justification = 3
  148.                 ELSE
  149.                     CommandError = TRUE
  150.                     PRINT "Multiple text justifications are not allowed:  "; Arguments$(i)
  151.                 END IF
  152.             ELSE
  153.                 CommandError = TRUE
  154.                 PRINT "Invalid switch:  "; Arguments$(i)
  155.             END IF
  156.         CASE "/S"
  157.             IF MID$(Arguments$(i), 3, 1) = ":" THEN
  158.                 ExpectedArg = VAL(MID$(Arguments$(i), 4, LEN(Arguments$(i))))
  159.                 IF (ExpectedArg > 0) AND (ExpectedArg < 31) THEN
  160.                     StartCol = ExpectedArg
  161.                 ELSE
  162.                     CommandError = TRUE
  163.                     PRINT "Invalid starting column:  "; MID$(Arguments$(i), 4, LEN(Arguments$(i)))
  164.                 END IF
  165.                 ExpectedArg = 0
  166.             ELSE
  167.                 CommandError = TRUE
  168.                 PRINT "Missing colon in switch:  "; Arguments$(i)
  169.             END IF
  170.         CASE "/E"
  171.             IF MID$(Arguments$(i), 3, 1) = ":" THEN
  172.                 ExpectedArg = VAL(MID$(Arguments$(i), 4, LEN(Arguments$(i))))
  173.                 IF (ExpectedArg > 49) AND (ExpectedArg < 81) THEN
  174.                     EndCol = ExpectedArg
  175.                 ELSE
  176.                     CommandError = TRUE
  177.                     PRINT "Invalid ending column:  "; MID$(Arguments$(i), 4, LEN(Arguments$(i)))
  178.                 END IF
  179.                 ExpectedArg = 0
  180.             ELSE
  181.                 CommandError = TRUE
  182.                 PRINT "Missing colon in switch:  "; Arguments$(i)
  183.             END IF
  184.         CASE "/T"
  185.             IF MID$(Arguments$(i), 3, 1) = ":" THEN
  186.                 ExpectedArg = VAL(MID$(Arguments$(i), 4, LEN(Arguments$(i))))
  187.                 IF (ExpectedArg > 0) AND (ExpectedArg < 25) THEN
  188.                     TopLine = ExpectedArg
  189.                 ELSE
  190.                     CommandError = TRUE
  191.                     PRINT "Invalid top line:  "; MID$(Arguments$(i), 4, LEN(Arguments$(i)))
  192.                 END IF
  193.                 ExpectedArg = 0
  194.             ELSE
  195.                 CommandError = TRUE
  196.                 PRINT "Missing colon in switch:  "; Arguments$(i)
  197.             END IF
  198.         CASE "/W"
  199.             IF LEN(Arguments$(i)) = 2 THEN
  200.                 WipeScreen = TRUE
  201.             ELSE
  202.                 CommandError = TRUE
  203.                 PRINT "Invalid switch:  "; Arguments$(i)
  204.             END IF
  205.         CASE "/$"
  206.             IF CommandError = FALSE THEN
  207.                 IF LEN(Arguments$(i)) = 2 THEN
  208.                     ShowGimme
  209.                 ELSE
  210.                     CommandError = TRUE
  211.                     PRINT "Invalid switch:  "; Arguments$(i)
  212.                 END IF
  213.             END IF
  214.         CASE "/D"
  215.             ON ERROR GOTO PrintDocError
  216.             IF CommandError = FALSE THEN
  217.                 IF MID$(Arguments$(i), 3, 1) = ":" THEN
  218.                     FileName$ = MID$(Arguments$(i), 4, LEN(Arguments$(i)))
  219.                     IF FileName$ <> "" THEN
  220.                         IF FileName$ <> "CLOCK$" THEN
  221.                             FileName$ = MID$(Arguments$(i), 4, LEN(Arguments$(i)))
  222.                         ELSE
  223.                             ERROR 25
  224.                         END IF
  225.                         CALL PrintDoc(FileName$)
  226.                     ELSE
  227.                         FileName$ = "DAYQUOTE.DOC"
  228.                         CALL PrintDoc(FileName$)
  229.                     END IF
  230.                 ELSE
  231.                     FileName$ = "DAYQUOTE.DOC"
  232.                     CALL PrintDoc(FileName$)
  233.                 END IF
  234.             END IF
  235.         CASE ELSE
  236.             IF LEFT$(Arguments$(i), 1) = "/" THEN
  237.                 CommandError = TRUE
  238.                 PRINT "Invalid switch:  "; Arguments$(i)
  239.             ELSE
  240.                 QuoteFile$ = Arguments$(i)
  241.             END IF
  242.         END SELECT
  243.     NEXT i
  244.  
  245.     IF QuoteFile$ = "" THEN
  246.         PRINT "Quote file not specified."
  247.         PRINT
  248.         PRINT "Type 'DAYQUOTE /?' for help."
  249.     ELSE
  250.         IF (CommandError) THEN
  251.             PRINT
  252.             PRINT "Type 'DAYQUOTE /?' for help."
  253.         ELSE
  254.             SELECT CASE QuoteFile$
  255.             CASE "CON", "AUX", "PRN", "CLOCK$", "COM1", "COM2"
  256.                 PRINT "Quote file can not be a reserved device name:  "; QuoteFile$
  257.             CASE "COM3", "COM4", "LPT1", "LPT2", "LPT3"
  258.                 PRINT "Quote file can not be a reserved device name:  "; QuoteFile$
  259.             CASE ELSE
  260.                 CALL DoQuote(QuoteFile$)
  261.             END SELECT
  262.         END IF
  263.     END IF
  264.  
  265.     SYSTEM
  266.  
  267.  
  268. QuoteFileError:
  269.     SELECT CASE ERR
  270.     CASE 6
  271.         PRINT "Overflow reading file:  "; QuoteFile$
  272.         PRINT QuoteFile$; " is too large."
  273.         SYSTEM
  274.     CASE 53
  275.         PRINT "Problem looking for quote file:  "; QuoteFile$
  276.         SYSTEM
  277.     CASE 57
  278.         PRINT "Unsupported disk format encountered looking for file:  "; QuoteFile$
  279.         SYSTEM
  280.     CASE 64
  281.         PRINT "Bad file name:  "; QuoteFile$
  282.         SYSTEM
  283.     CASE 71
  284.         PRINT "Drive not ready looking for quote file:  "; QuoteFile$
  285.         SYSTEM
  286.     CASE 76
  287.         PRINT "Path not found looking for quote file:  "; QuoteFile$
  288.         SYSTEM
  289.     CASE ELSE
  290.         PRINT "System error number #"; LTRIM$(STR$(ERR)); " handling quote file:  "; QuoteFile$
  291.         PRINT "- "; ErrorString$(ERR); " -"
  292.         SYSTEM
  293.     END SELECT
  294.  
  295. PrintDocError:
  296.     SELECT CASE ERR
  297.     CASE 25
  298.         SELECT CASE FileName$
  299.         CASE "CLOCK$"
  300.             PRINT "Are you really that determined to fuck things up?"
  301.         CASE "PRN"
  302.             PRINT "Printer is not responding at attempt to print file."
  303.         CASE "COM1", "COM2", "COM3", "COM4", "LPT1", "LPT2", "LPT3"
  304.             PRINT FileName$; " is not responding at attempt to print file."
  305.         CASE ELSE
  306.             PRINT "Device fault error printing to file:  "; FileName$
  307.         END SELECT
  308.         SYSTEM
  309.     CASE 57
  310.         PRINT "Unsupported disk format encountered printing to file:  "; FileName$
  311.         SYSTEM
  312.     CASE 64
  313.         PRINT "Bad file name:  "; FileName$
  314.         SYSTEM
  315.     CASE 68
  316.         PRINT "Path not found printing to file:  "; FileName$
  317.         SYSTEM
  318.     CASE 71
  319.         PRINT "Drive not ready printing to file:  "; FileName$
  320.         SYSTEM
  321.     CASE 75
  322.         SELECT CASE TryDirectory
  323.         CASE FALSE
  324.             TryDirectory = TRUE
  325.             SELECT CASE RIGHT$(FileName$, 1)
  326.             CASE ":", "\"
  327.                 FileName$ = FileName$ + "DAYQUOTE.DOC"
  328.             CASE ELSE
  329.                 FileName$ = FileName$ + "\DAYQUOTE.DOC"
  330.             END SELECT
  331.             RESUME
  332.         CASE ELSE
  333.             PRINT "Path not found printing to file:  "; FileName$
  334.             SYSTEM
  335.         END SELECT
  336.     CASE 76
  337.         PRINT "Path not found printing to file:  "; FileName$
  338.         SYSTEM
  339.     CASE ELSE
  340.         IF ERR = 61 THEN KILL FileName$: PRINT
  341.         PRINT "System error number #"; LTRIM$(STR$(ERR)); " printing to file:  "; FileName$
  342.         PRINT "- "; ErrorString$(ERR); " -"
  343.         SYSTEM
  344.     END SELECT
  345.  
  346. MiscErrors:
  347.     SELECT CASE ERR
  348.     CASE ELSE
  349.         PRINT "System error number #"; LTRIM$(STR$(ERR)); " displaying quote from file:  "; QuoteFile$
  350.         PRINT "- "; ErrorString$(ERR); " -"
  351.         SYSTEM
  352.     END SELECT
  353.  
  354.  
  355. '════════════════════════════════════════════════════════════════════════════
  356. '   BASIC ERRor string data
  357. '════════════════════════════════════════════════════════════════════════════
  358.     DATA "NEXT without FOR"
  359.     DATA "Syntax error"
  360.     DATA "RETURN without GOSUB"
  361.     DATA "Out of DATA"
  362.     DATA "Illegal function call"
  363.     DATA "Overflow"
  364.     DATA "Out of memory"
  365.     DATA "Undefined line number"
  366.     DATA "Subscript out of range"
  367.     DATA "Duplicate definition"
  368.     DATA "Division by zero"
  369.     DATA "Illegal direct"
  370.     DATA "Type mismatch"
  371.     DATA "Out of string space"
  372.     DATA "String too long"
  373.     DATA "String formula too complex"
  374.     DATA "Can't continue"
  375.     DATA "Undefined user function"
  376.     DATA "No RESUME"
  377.     DATA "RESUME without error"
  378.     DATA "Description not found"
  379.     DATA "Missing operand"
  380.     DATA "Line buffer overflow"
  381.     DATA "Device timeout"
  382.     DATA "Device fault"
  383.     DATA "FOR without NEXT"
  384.     DATA "Out of paper"
  385.     DATA "Description not found"
  386.     DATA "WHILE without WEND"
  387.     DATA "WEND without WHILE"
  388.     DATA "Description not found"
  389.     DATA "Description not found"
  390.     DATA "Description not found"
  391.     DATA "Description not found"
  392.     DATA "Description not found"
  393.     DATA "Description not found"
  394.     DATA "Description not found"
  395.     DATA "Description not found"
  396.     DATA "Description not found"
  397.     DATA "Description not found"
  398.     DATA "Description not found"
  399.     DATA "Description not found"
  400.     DATA "Description not found"
  401.     DATA "Description not found"
  402.     DATA "Description not found"
  403.     DATA "Description not found"
  404.     DATA "Description not found"
  405.     DATA "Description not found"
  406.     DATA "Description not found"
  407.     DATA "FIELD overflow"
  408.     DATA "Internal error"
  409.     DATA "Bad file number"
  410.     DATA "File not found"
  411.     DATA "Bad file mode"
  412.     DATA "File already open"
  413.     DATA "Description not found"
  414.     DATA "Device I/O error"
  415.     DATA "File already exists"
  416.     DATA "Description not found"
  417.     DATA "Description not found"
  418.     DATA "Disk full"
  419.     DATA "Input past end"
  420.     DATA "Bad record number"
  421.     DATA "Bad file name"
  422.     DATA "Description not found"
  423.     DATA "Direct statement in file"
  424.     DATA "Too many files"
  425.     DATA "Device unavailable"
  426.     DATA "Communication buffer overflow"
  427.     DATA "Disk write-protected - Permission denied"
  428.     DATA "Disk not ready"
  429.     DATA "Disk media error"
  430.     DATA "Advanced feature"
  431.     DATA "Rename across disks"
  432.     DATA "Path/file access error"
  433.     DATA "Path not found"
  434.  
  435. Sub DoQuote (QuoteFile$)
  436.  
  437.     On Error GoTo QuoteFileError
  438.   
  439.     Open QuoteFile$ For Input As #1
  440.     Close #1
  441.  
  442.     Open QuoteFile$ For Binary As #1
  443.  
  444.     If LOF(1) = 0 Then
  445.         Print "Attempt to read an empty file:  "; QuoteFile$
  446.         Close #1
  447.         Exit Sub
  448.     End If
  449.    
  450.     Randomize Timer
  451.     Position! = Fix(Rnd * LOF(1)) + 2
  452.  
  453.     Do While BeginningFound = False
  454.         Get #1, Position!, Dummy%
  455.         Char$ = Left$(MKI$(Dummy%), 1)
  456.       
  457.         Select Case Char$
  458.         Case Chr$(13), Chr$(10)
  459.             Count = Count + 1
  460.             If Count = 4 Then
  461.                 If BeginningReady = True Then
  462.                     If (Fix(Rnd * 10) + 1) > 3 Then
  463.                         BeginningFound = True
  464.                     Else
  465.                         BeginningReady = False
  466.                         Count = 0
  467.                     End If
  468.                 End If
  469.             End If
  470.         Case Chr$(32), Chr$(9)
  471.             Count = 0
  472.         Case Chr$(0) To Chr$(8), Chr$(11), Chr$(12), Chr$(26), Chr$(29), Chr$(30)
  473.             Print "Attempt to read a binary file or non-text characters found in:  "; QuoteFile$
  474.             If Position! < 100 Then
  475.                 Position! = Position! + (100 - Position!)
  476.             Else
  477.                 Position! = Position! - 100
  478.             End If
  479.             BreakPos! = Position!
  480.             StartPos! = Position!
  481.             Print
  482.             Print "Reference block:"
  483.             Print String$(80, "─");
  484.             Do While Done = False
  485.                 If (Position! = LOF(1)) Then Done = True
  486.                 If (Position! = BreakPos! + 200) Then Done = True
  487.                 Get #1, Position!, Dummy%
  488.                 Char$ = Left$(MKI$(Dummy%), 1)
  489.                 Select Case Char$
  490.                 Case Chr$(10)
  491.                     If Last$ <> Chr$(13) Then
  492.                         Print Char$;
  493.                     End If
  494.                 Case Chr$(7), Chr$(11), Chr$(12), Chr$(29), Chr$(30)
  495.                 Case Else
  496.                     Print Char$;
  497.                 End Select
  498.                 Position! = Position! + 1
  499.                 Last$ = Char$
  500.             Loop
  501.             Print String$(80, "─")
  502.             Print "found at location"; StartPos!; "to"; Position!
  503.             Close #1
  504.             Exit Sub
  505.         Case Else
  506.             BegPos! = Position!
  507.             BeginningReady = True
  508.             Count = 0
  509.         End Select
  510.  
  511.         Size% = Size% + 1
  512.         If Size% > 1672 Then
  513.             Print "File read error - size of object in:  "; QuoteFile$
  514.             Print QuoteFile$; " is possibly not a quote file."
  515.             Close #1
  516.             Exit Sub
  517.         End If
  518.      
  519.         Position! = Position! - 1
  520.         If Position! = 0 Then
  521.             If BeginningReady = True Then
  522.                 BeginningFound = True
  523.             Else
  524.                 Position! = LOF(1)
  525.             End If
  526.         End If
  527.     Loop
  528.    
  529.     Count = 0
  530.     Size% = 0
  531.     Position! = BegPos!
  532.   
  533.     Do While EndingFound = False
  534.         If Position! = LOF(1) Then EndingFound = True
  535.         Get #1, Position!, Dummy%
  536.         Char$ = Left$(MKI$(Dummy%), 1)
  537.       
  538.         Select Case Char$
  539.         Case Chr$(13), Chr$(10)
  540.             If Int(Count / 2) = Count / 2 Then Quote$ = Quote$ + Chr$(32)
  541.             Last$ = Chr$(32)
  542.             Count = Count + 1
  543.             If EndingReady = True Then
  544.                 Count = 0
  545.                 EndingFound = True
  546.             End If
  547.             If Count = 2 Then
  548.                 EndingReady = True
  549.             End If
  550.             If Position! = LOF(1) Then
  551.                 Count = 0
  552.                 EndingFound = True
  553.             End If
  554.         Case Chr$(32), Chr$(9)
  555.             If Last$ <> Char$ Then Quote$ = Quote$ + Char$
  556.             Count = 0
  557.         Case Chr$(0) To Chr$(8), Chr$(11), Chr$(12), Chr$(26), Chr$(29), Chr$(30)
  558.             Print "Attempt to read a binary file or non-text characters found in:  "; QuoteFile$
  559.             If Position! < 100 Then
  560.                 Position! = Position! + (100 - Position!)
  561.             Else
  562.                 Position! = Position! - 100
  563.             End If
  564.             BreakPos! = Position!
  565.             StartPos! = Position!
  566.             Print
  567.             Print "Reference block:"
  568.             Print String$(80, "─");
  569.             Do While Done = False
  570.                 If (Position! = LOF(1)) Then Done = True
  571.                 If (Position! = BreakPos! + 200) Then Done = True
  572.                 Get #1, Position!, Dummy%
  573.                 Char$ = Left$(MKI$(Dummy%), 1)
  574.                 Select Case Char$
  575.                 Case Chr$(10)
  576.                     If Prev$ <> Chr$(13) Then
  577.                         Print Char$;
  578.                     End If
  579.                 Case Chr$(7), Chr$(11), Chr$(12), Chr$(29), Chr$(30)
  580.                 Case Else
  581.                     Print Char$;
  582.                 End Select
  583.                 Position! = Position! + 1
  584.                 Prev$ = Char$
  585.             Loop
  586.             Print String$(80, "─")
  587.             Print "found at location"; StartPos!; "to"; Position!
  588.             Close #1
  589.             Exit Sub
  590.         Case Else
  591.             Quote$ = Quote$ + Char$
  592.             If EndingReady = True Then EndingReady = False
  593.             Count = 0
  594.         End Select
  595.       
  596.         Size% = Size% + 1
  597.         If Size% > 1672 Then
  598.             Print "File read error - size of object in:  "; QuoteFile$
  599.             Print "  "; QuoteFile$; " is possibly not a quote file."
  600.             Close #1
  601.             Exit Sub
  602.         End If
  603.     
  604.         Position! = Position! + 1
  605.         Last$ = Char$
  606.     Loop
  607.     Count = 0
  608.   
  609.     Close #1
  610.  
  611.     If Quote$ <> "" Then
  612.         Quote$ = LTrim$(RTrim$(Quote$)) + Chr$(32)
  613.         Call PutQuote(Quote$)
  614.     Else
  615.         Print "No quotes found in file:  ", QuoteFile$
  616.         Exit Sub
  617.     End If
  618.  
  619. End Sub
  620.  
  621. Sub ParseCommandLine (NumArgs%, Args$())
  622.  
  623.     NumArgs% = 0: in = FALSE: switch = FALSE
  624.     Comline$ = Command$
  625.     Length = Len(Comline$)
  626.     For Increment = 1 To Length
  627.         Char$ = Mid$(Comline$, Increment, 1)
  628.         Select Case Char$
  629.         Case Chr$(32), Chr$(9)
  630.             If (in) Then
  631.                 If NumArgs% = 20 Then Exit For
  632.                 NumArgs% = NumArgs% + 1
  633.                 in = False
  634.             End If
  635.         Case "/"
  636.             If (in) Or (NumArgs% = 0) Then NumArgs% = NumArgs% + 1
  637.             in = True
  638.             Args$(NumArgs%) = Args$(NumArgs%) + Char$
  639.         Case Else
  640.             If (NumArgs% = 0) Then NumArgs% = NumArgs% + 1
  641.             in = True
  642.             Args$(NumArgs%) = Args$(NumArgs%) + Char$
  643.         End Select
  644.     Next Increment
  645.  
  646.     If NumArgs% > 0 Then If Args$(NumArgs%) = "" Then NumArgs% = NumArgs% - 1
  647.  
  648. End Sub
  649.  
  650. Sub PutQuote (Text$)
  651.  
  652.     On Error GoTo MiscErrors
  653.  
  654.     CurrentLine = CSRLIN
  655.    
  656.     If StartCol = 0 Then StartCol = 10
  657.     If EndCol = 0 Then EndCol = 70
  658.     If TopLine = 0 Then TopLine = CurrentLine
  659.    
  660.     QuoteWidth = EndCol - StartCol + 1 - 4
  661.     StringLength = Len(Text$) - 1           ' -1 nullifies terminating char
  662.    
  663.     If StringLength > QuoteWidth Then
  664.         If (StringLength / QuoteWidth) = Int(StringLength / QuoteWidth) Then
  665.             NumLines = StringLength / QuoteWidth
  666.         Else
  667.             NumLines = Int(StringLength / QuoteWidth) + 1
  668.         End If
  669.     Else
  670.         NumLines = 1
  671.     End If
  672.  
  673.     If NumLines > 21 Then
  674.         Print "Quote text is too long to fit in the specified frame."
  675.         Exit Sub
  676.     End If
  677.  
  678.     If InStr(Text$, "~~") Then
  679.         MarkPos = InStr(Text$, "~~")
  680.         AttribName$ = "- " + Left$(RTrim$(Mid$(Text$, MarkPos + 2, StringLength - MarkPos + 2)), QuoteWidth)
  681.         AttribText$ = Space$(QuoteWidth - Len(AttribName$)) + AttribName$
  682.         Text$ = RTrim$(Left$(Text$, MarkPos - 1)) + Chr$(32)
  683.         Attribute = True
  684.     End If
  685.  
  686. Compensate:
  687.  
  688.     For j = 1 To NumLines
  689.         Portion$ = Mid$(Text$, LastRef + 1, QuoteWidth + 1)
  690.         For k = Len(Portion$) To 1 Step -1
  691.             If Mid$(Portion$, k, 1) = Chr$(32) Then
  692.                 QuoteText$(j) = LTrim$(RTrim$(Mid$(Portion$, 1, k - 1)))
  693.                 LastRef = LastRef + k
  694.                 Exit For
  695.             ElseIf k = 1 Then
  696.                 QuoteText$(j) = Mid$(Portion$, 1, Len(Portion$) - 2) + "-"
  697.                 LastRef = LastRef + Len(Portion$) - 2
  698.                 Exit For
  699.             Else
  700.                 QuoteText$(j) = LTrim$(RTrim$(Mid$(Portion$, 1, k)))
  701.             End If
  702.         Next k
  703.  
  704.         If j = NumLines Then
  705.             If Right$(QuoteText$(j), 1) <> Mid$(Text$, StringLength, 1) Then
  706.                 LastRef = 0
  707.                 NumLines = NumLines + 1
  708.                 If NumLines > 21 Then
  709.                     Print "Quote text is too long to fit in the specified frame."
  710.                     Exit Sub
  711.                 End If
  712.                 GoTo Compensate
  713.             End If
  714.         End If
  715.   
  716.     Next j
  717.    
  718.     If Attribute = True Then QuoteText$(j - 1) = AttribText$
  719.   
  720.     If (TopLine + NumLines) > 22 Then
  721.         TopLine = TopLine - ((TopLine + NumLines) - 22)
  722.         Print String$(NumLines + 1, Chr$(10))
  723.     End If
  724.  
  725.     If WipeScreen = True Then Cls
  726.  
  727.     If ForeColor > 0 Then COLOR ForeColor - 1
  728.     IF BackColor > 0 THEN COLOR , BackColor - 1
  729.    
  730.     LOCATE TopLine, StartCol
  731.     Print "╔"; String$(QuoteWidth + 2, "═"); "╗";
  732.  
  733.     For i = 1 To NumLines
  734.         j = TopLine + i
  735.  
  736.         LOCATE j, StartCol
  737.         Print "║"; String$(QuoteWidth + 2, " "); "║";
  738.                    
  739.         Select Case Justification
  740.         Case 1        'LEFT
  741.             LOCATE j, StartCol + 2
  742.         Case 2        'CENTERED
  743.             LOCATE j, StartCol + 2 + Int((QuoteWidth - Len(QuoteText$(i))) / 2)
  744.         Case 3        'RIGHT
  745.             LOCATE j, StartCol + 2 + (QuoteWidth - Len(QuoteText$(i)))
  746.         Case Else     'LEFT DEFAULT
  747.             LOCATE j, StartCol + 2
  748.         End Select
  749.         Print QuoteText$(i);
  750.     Next i
  751.  
  752.     LOCATE j + 1, StartCol
  753.     Print "╚"; String$(QuoteWidth + 2, "═"); "╝";
  754.    
  755.     If j + 2 > CurrentLine Then CurrentLine = j + 2
  756.  
  757.     COLOR 7, 0
  758.     Print ;
  759.    
  760.     LOCATE CurrentLine, 1
  761.  
  762. End Sub
  763.  
  764. Sub ShowGimme ()
  765.  
  766.     Print
  767.     Print "       ┌──────────────────────────────────────────────────────────────┐         ";
  768.     Print "       │ Dayquote 1.0  ─  Copyright 1994, 1995 by Freeware Unlimited. │         ";
  769.     Print "       ├──────────────────────────────────────────────────────────────┤         ";
  770.     Print "       │                                                              │         ";
  771.     Print "       │  That's Right!  If you send me money, then I'll send 10% of  │         ";
  772.     Print "       │  it directly back to you!!!  The more money you send to me,  │         ";
  773.     Print "       │  the more money that will be sent to *YOU*...  Think of it!  │         ";
  774.     Print "       │                                                              │         ";
  775.     Print "       │  As a FREE bonus,  I'll also send you a catalog,  if I have  │         ";
  776.     Print "       │  one finished, as well as MORE FREE SOFTWARE, if I have any  │         ";
  777.     Print "       │  more programs done.  If you'll tell me what this program's  │         ";
  778.     Print "       │  version number is, I'll ALSO send you a FREE UPGRADE,  if,  │         ";
  779.     Print "       │  of course, there is one available.  Thank you, in advance.  │         ";
  780.     Print "       │                                                              │         ";
  781.     Print "       │                                                              │         ";
  782.     Print "       │      ──────────────  FreeWare Unlimited  ──────────────      │         ";
  783.     Print "       │                                                              │         ";
  784.     Print "       │       12316 138th Street  ∞  Largo, Florida 34644-3016       │         ";
  785.     Print "       │                                                              │         ";
  786.     Print "       └──────────────────────────────────────────────────────────────┘         ";
  787.     Print
  788.  
  789.     SYSTEM
  790.  
  791. End Sub
  792.  
  793. Sub ShowHelp ()
  794.  
  795.     Print
  796.     Print "       ┌──────────────────────────────────────────────────────────────┐         ";
  797.     Print "       │ DayQuote 1.0  ─  Copyright 1994, 1995 by Freeware Unlimited. │         ";
  798.     Print "       ├──────────────────────────────────────────────────────────────┤         ";
  799.     Print "       │ Usage: DAYQUOTE [switches] quotefil.ext                      │         ";
  800.     Print "       │                                                              │         ";
  801.     Print "       │  Switches:                                                   │         ";
  802.     Print "       │   /?     - Shows this help screen.                           │         ";
  803.     Print "       │   /F:c   - Use foreground color 'c', as listed below.        │         ";
  804.     Print "       │   /B:c   - Use background color 'c', as listed below.        │         ";
  805.     Print "       │   /L     - Left-justify the text.                            │         ";
  806.     Print "       │   /R     - Right-justify the text.                           │         ";
  807.     Print "       │   /C     - Center the text.                                  │         ";
  808.     Print "       │   /S:#   - Start at specified column # (1-30). Default = 10  │         ";
  809.     Print "       │   /E:#   - End at specified column # (50-80).  Default = 70  │         ";
  810.     Print "       │   /T:#   - Top line # to begin on (1-24). Default = current  │         ";
  811.     Print "       │   /W     - Wipe (clear) the screen before displaying.        │         ";
  812.     Print "       │   /D[:n] - Create documentation file, DAYQUOTE.DOC, or 'n'.  │         ";
  813.     Print "       │   /$     - Get money sent to you.                            │         ";
  814.     Print "       │                                                              │         ";
  815.     Print "       │    Available foreground colors and background colors are:    │         ";
  816.     Print "       │                                                              │         ";
  817.     Print "       │  BLACK, BLUE, GREEN, CYAN, RED, MAGENTA, BROWN, WHITE, GRAY  │         ";
  818.     Print "       │  LTBLUE, LTGREEN, LTCYAN, LTRED, LTMAGENTA, YELLOW, BRWHITE  │         ";
  819.     Print "       └──────────────────────────────────────────────────────────────┘         ";
  820.  
  821.     SYSTEM
  822.  
  823. End Sub
  824.  
  825. Sub ShowSyntax ()
  826.  
  827.     Print "Usage: DAYQUOTE [switches] quotefil.ext"
  828.     Print
  829.     Print "(Type 'DAYQUOTE /?' for help.)"
  830.     SYSTEM
  831.  
  832. End Sub
  833.  
  834.